package com.dongdongshop.controller;

import com.dongdongshop.data.PageBean;
import com.dongdongshop.data.Result;
import com.dongdongshop.data.ResultEnum;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.pojo.TbStatus;
import com.dongdongshop.service.SellerService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("sellerCon")
public class AdminController {

    @DubboReference
    private SellerService sellerService;

    @RequestMapping("seller")
    public String seller(Model model) {
        List<TbStatus> statusList = sellerService.getList();
        model.addAttribute("status",statusList);
        return "admin/seller_1";
    }

    @RequestMapping("getSellerInfo")
    @ResponseBody
    public Result getSellerInfo(String name,String nickName,String status) {
        try {
            List<TbSeller> pb = sellerService.getSellerInfo(name,nickName);
            return Result.ok().setData(pb);
        }catch (Exception e) {
            return Result.respones(ResultEnum.ERROR);
        }
    }

    @RequestMapping("getOneSellerInfo")
    @ResponseBody
    public Result getOneSellerInfo(String sellerId) {
        try {
            TbSeller tbSeller = sellerService.getOneSellerInfo(sellerId);
            return Result.ok().setData(tbSeller);
        }catch (Exception e) {
            return Result.respones(ResultEnum.ERROR);
        }
    }

    @RequestMapping("setStatus")
    @ResponseBody
    public Result setStatus(String status,String sellerId) {
        try {
            sellerService.setStatus(status,sellerId);
            return Result.respones(ResultEnum.SUCCESS);
        }catch (Exception e) {
            return Result.respones(ResultEnum.ERROR);
        }
    }
}

